package cn.cmdr.service.ServiceImpl;

import cn.cmdr.mapper.ReturnReasonMapper;
import cn.cmdr.pojo.ReturnReason;
import cn.cmdr.service.ReturnReasonService;
import cn.cmdr.vo.PageVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service("returnReasonService")
public class ReturnReasonServiceImpl extends ServiceImpl<ReturnReasonMapper, ReturnReason> implements ReturnReasonService {
    @Resource
    private ReturnReasonMapper returnReasonMapper;

    @Override
    public List<ReturnReason> getReturnReasonList() {
        return returnReasonMapper.selectList(null);
    }

    @Override
    public PageVo getPageReturnReasonList(Integer pageNo, Integer pageSize, ReturnReason returnReason) {
        Page page = new Page();
        page.setSize(pageSize);
        page.setCurrent(pageNo);
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.orderByAsc("return_sort");
        IPage<ReturnReason> iPage = super.page(page,queryWrapper);
        return new PageVo(iPage.getRecords(),iPage.getTotal());
    }

    @Override
    public void getReturnReasonUpdate(ReturnReason returnReason) {
        returnReasonMapper.updateById(returnReason);
    }

    @Override
    public void getReturnReasonAdd(ReturnReason returnReason) {
        returnReasonMapper.insert(returnReason);
    }

    @Override
    public void getReturnReasonDelete(Integer id) {
        returnReasonMapper.deleteById(id);
    }

    @Override
    public List<ReturnReason> getList(Integer state) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("return_state",state);
        return returnReasonMapper.selectList(queryWrapper);
    }

}
